package utils;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class DrawView extends View implements OnTouchListener {

    Paint paintX = new Paint();
    Paint paintY = new Paint();
    int X=13;
    int Y=6;

    public DrawView(Context context, AttributeSet attrs) {
        super(context,attrs);
        
        this.setMinimumHeight((int)(this.getWidth()/1.6));
        
        setFocusable(true);
        setFocusableInTouchMode(true);
        this.setOnTouchListener(this);
        this.setBackgroundColor(Color.rgb(0, 90, 0));
        
        paintX.setColor(Color.rgb(255, 255, 160));
        paintX.setAntiAlias(true);
        paintX.setStrokeWidth(2);
        
        paintY.setColor(Color.rgb(255, 255, 160));
        paintY.setAntiAlias(true);
        paintY.setStrokeWidth(2);
        
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
    
    
    @Override
    public void onDraw(Canvas canvas) {
    	canvas.drawLine(X*(this.getWidth()/25), 0 , X*(this.getWidth()/25), this.getHeight(), paintY);
    	canvas.drawLine(0, Y*(this.getHeight()/10) , this.getWidth(),  Y*(this.getHeight()/10), paintY);
    }

    public boolean onTouch(View view, MotionEvent event) {
        return true;
    }
    
    public int buttonPlusX(){
    	if (X <= 25){
    		X++;
        	invalidate();	
    	}
    	return X;
    }
    
    public int buttonPlusY(){
    	if (Y >= 2){
    		Y--;
        	invalidate();
    	}
    	return Y;
    }

    public int buttonMoinsX(){
    	if (X >= 2 ){
    		X--;
    		invalidate();
    	}
    	return X;
    }

    public int buttonMoinsY(){
    	if (Y <= 8 ){
    		Y++;
    		invalidate();
    	}
    	return Y;
    }
}